<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>

  <!-- 这个位置不推荐：放这里时，DOM都还没加载完，根本操作不了DOM -->
  <!-- <script>
    document.querySelector('.title').onclick = function() {
      alert('点击了h2标签')
    }
  </script> -->
</head>
<body>
  <h2 class="title">hahahaha</h2>

  <!-- 推荐摆放的位置 -->
  <script>
    document.querySelector('.title').onclick = function() {
      alert('点击了h2标签')

      // 严格区分大小写
      ALERT('Hello JavaScript')
    }
  </script>
</body>
</html>